package com.utils;
import com.entity.MethodLog;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Map;

public class AnnotationUtil
{
    //修改方法上的MethodLog注解值s
    public static void setOperateInfo( Class cla , String methodName , String operateInfo , Class [] classes )
    {
        try
        {
            Method method = cla.getMethod( methodName, classes );
            MethodLog methodLog = method.getAnnotation( MethodLog.class );
            InvocationHandler invocationHandler = Proxy.getInvocationHandler( methodLog );
            Field value = invocationHandler.getClass().getDeclaredField("memberValues");
            value.setAccessible(true);
            Map<String, Object> memberValues = (Map<String, Object>)value.get(invocationHandler);
            String val = operateInfo;
            memberValues.put("operateInfo", val);
        }
        catch ( Exception e )
        {
            System.out.println( "AnnotationUtil类的changeAnnotationValue方法出错" );
            e.printStackTrace();
        }
    }
}
